import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 边积分最高的节点
 * @USER: Administrator
 * @DATE: 2024/9/21 上午8:54
 * @VERSION: 1.0.0
 */
public class LC2374 {
    public static void main(String[] args) {
        LC2374 lc2374 = new LC2374();
        System.out.println(lc2374.edgeScore(new int[]{25,27,27,21,39,30,38,17,36,23,23,2,34,39,11,36,15,29,35,36,39,3,30,29,33,0,33,21,41,21,36,36,35,35,19,36,42,19,28,11,44,11,30,6,11}));
    }
    public int edgeScore(int[] edges) {
        Long maxScore = Long.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        Map<Integer, Long> map = new HashMap<>();
        for (int i = 0; i < edges.length; i++) {
            map.put(edges[i], map.getOrDefault(edges[i], 0L) + i);
        }

        // 获取最大分数
        for (Integer i : map.keySet()) {
            if (map.get(i) > maxScore) {
                maxScore = map.get(i);
            }
        }

        for (Integer i : map.keySet()) {
            if (Objects.equals(map.get(i), maxScore)) {
                if (min>i){
                    min = i;
                }
            }
        }
        return min;
    }
}
